package com.edu.smsys.controller;

import com.edu.smsys.model.form.CensusAddForm;
import com.edu.smsys.model.form.CensusQueryForm;
import com.edu.smsys.model.form.CensusUpdateForm;
import com.edu.smsys.model.vo.CensusVO;
import com.edu.smsys.service.impl.CensusService;
import com.edu.smsys.service.impl.StudentService;
import com.edu.smsys.service.impl.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 学籍管理控制器
 */
@Controller
@RequestMapping("/census")
public class CensusController extends BaseController {
    @Autowired
    private CensusService censusService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private TeacherService teacherService;

    /**
     * 查询所有学籍信息
     * @param model
     * @return
     */
    @RequestMapping("/censuslist")
    public String censusList(Model model){
        List<CensusVO> voList=censusService.findCensusAll();
        model.addAttribute("voList",voList);
        return VIEW_CONTENT+ "census/censuslist";
    }

    /**
     * 修改学籍信息
     *
     * @param form
     * @return
     */
    @RequestMapping("/update")
    public String update(CensusUpdateForm form) {
        censusService.updateEntity(form);
        return "redirect:/census/censuslist";
    }

    /**
     * 删除学籍信息
     *
     * @param id 要删除的id
     * @return
     */
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable("id") int id) {
        censusService.deleteEntity(id);
        return "redirect:/census/censuslist";
    }

    /**
     * 添加学籍信息
     * @return
     */
    @RequestMapping("/add")
    public String add(){
        return VIEW_CONTENT+ "census/addcensus";
    }

    /**
     * 添加学籍信息的动作
     * @param form
     * @return
     */
    @RequestMapping("/adddo")
    public String add(CensusAddForm form){
        censusService.addEntity(form);
        return "redirect:/census/censuslist";
    }

    /**
     * 根据条件查询
     * @return
     */
    @RequestMapping("/query")
    public String query(CensusQueryForm form,Model model){
       List<CensusVO> voList= censusService.findCensusVOByform(form);
        model.addAttribute("voList",voList);
        return VIEW_CONTENT+ "census/censuslist";
    }
}
